package priv.demos.demo1.solution.main;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created on 2017/5/4.
 */
public class Solution {

    private static List<Roman> romans = new ArrayList<>();

    static {
        romans.add(new Roman(1000, "M"));
        romans.add(new Roman(900, "CM"));
        romans.add(new Roman(800, "DCCC"));
        romans.add(new Roman(700, "DCC"));
        romans.add(new Roman(600, "DC"));
        romans.add(new Roman(500, "D"));
        romans.add(new Roman(400, "CD"));
        romans.add(new Roman(300, "CCC"));
        romans.add(new Roman(200, "CC"));
        romans.add(new Roman(100, "C"));
        romans.add(new Roman(90, "XC"));
        romans.add(new Roman(80, "LXXX"));
        romans.add(new Roman(70, "LXX"));
        romans.add(new Roman(60, "LX"));
        romans.add(new Roman(50, "L"));
        romans.add(new Roman(40, "XL"));
        romans.add(new Roman(30, "XXX"));
        romans.add(new Roman(20, "XX"));
        romans.add(new Roman(10, "X"));
        romans.add(new Roman(9, "IX"));
        romans.add(new Roman(8, "VIII"));
        romans.add(new Roman(7, "VII"));
        romans.add(new Roman(6, "VI"));
        romans.add(new Roman(5, "V"));
        romans.add(new Roman(4, "IV"));
        romans.add(new Roman(3, "III"));
        romans.add(new Roman(2, "II"));
        romans.add(new Roman(1, "I"));
    }

    public static void main(String[] args) {

        Map map = JSON.parseObject(null, Map.class);
        System.out.println("map = " + map);

        int num = 0;

        int n = num;
        if (n < 1 && n > 3999) {
            return;
        }
        StringBuffer ret = new StringBuffer();
        for (int i = 0; i < romans.size() && n > 0; ) {
            Roman roman = romans.get(i);
            if (n >= roman.getNum()) {
                n -= roman.getNum();
                ret.append(roman.getRomanCode());
            }else {
                i++;
            }
        }
        System.out.println(ret);
    }

    static class Roman {
        private int num;
        private String romanCode;

        public Roman(int num, String romanCode) {
            this.num = num;
            this.romanCode = romanCode;
        }

        public int getNum() {
            return num;
        }

        public String getRomanCode() {
            return romanCode;
        }
    }
}
